<?php
FLEA::loadClass('Controller_Public');

class Controller_MngrLabel extends Controller_Public
{	
	var $tableLabels;
	function Controller_MngrLabel()
    {
        $this->tableLabels = FLEA::getSingleton('Model_Labels');
	}
	
	function actionList()
	{
		if (isset($_GET['result'])) {
            $result = (int)$_GET['result'];
        }

		$args = $_GET['args'];
		
		if ($result > 0) {
			if ( $args == 'add' )
				$message = "<div id=\"message\" class=\"updated fade\"><p><strong>厂牌添加成功。</strong> </p></div>";
			else if ($args == 'edit')
				$message = "<div id=\"message\" class=\"updated fade\"><p><strong>厂牌修改成功。</strong> </p></div>";
		} else {
			$message = '';
		}
		
		$smarty = &$this->_getView();
		$smarty->assign('menuName', $this->getMenuName());
		$smarty->assign('labelList', $this->tableLabels->findAll(null, 'label_id ASC'));
		$smarty->assign('message', $message);		
		$smarty->display($this->getTemplates());
	}
	
	function actionAdd()
	{
		$smarty = &$this->_getView();
		$smarty->assign('menuName', $this->getMenuName());
		$smarty->display($this->getTemplates());
	}
	
	function actionAdded()
	{
		$data = array(
            'label_name' => $_POST['label_name'],   
			'label_url' => $_POST['label_url'],
        );

		$ret = $this->tableLabels->save($data);	
		
		redirect(url('mngrlabel', 'list',array('result' => $ret,'args'=>'add')));
		
	}

	function actionEdit()
	{
		if (isset($_GET['label_id'])) {
            $label_id = (int)$_GET['label_id'];
        }

		$condition = 'label_id = '.$label_id;
		$label = $this->tableLabels->find($condition);

		$smarty = &$this->_getView();
		$smarty->assign('menuName', $this->getMenuName());
		$smarty->assign('label', $label);
		$smarty->display($this->getTemplates());
	}

	function actionUpdate()
	{
		/*if (isset($_GET['artist_id'])) {
            $artist = $this->tableArtists->find((int)$_GET['artist_id']);
        }*/

		$data = array(
			'label_id' => $_POST['label_id'],
            'label_name' => $_POST['label_name'],
            'label_url' => $_POST['label_url'],
        );

		$ret = $this->tableLabels->save($data);	
		redirect(url('mngrlabel', 'list',array('result' => $ret,'args'=>'edit')));
		
	}
	
	/**
	 获取指定label下的专辑
	*/
	function actionAlbum()
	{
		if (isset($_GET['label_id'])) {
            $label_id = (int)$_GET['label_id'];
        }
		$tableAlbums = FLEA::getSingleton('Model_Albums');

		$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;

		FLEA::loadClass('Controller_Pager');
		$condition = 'label_id='.$label_id;
		$pager = &new Controller_Pager($tableAlbums, $page-1,FLEA::getAppInf('pageSize'),$condition);

		$smarty = &$this->_getView();
		$smarty->assign('menuName', $this->getMenuName());
		$smarty->assign('albumList', $pager->findAll('album_id,album_name,artist_id,label_id,album_thumb,release_date', 'album_id DESC'));
		$smarty->assign('message', $message);	
        $smarty->assign('page_info',$pager->getNavBar(url('mngrlabel','album',array('label_id'=>$label_id))) );
		$smarty->display('mngralbum_list.html');
	}
} 